package com.lngsyz.ywtb.biz.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lngsyz.ywtb.entity.biz.SealInfo;
import com.lngsyz.ywtb.entity.source1.YwtbCityOrderSeal;
import com.lngsyz.ywtb.enumeration.SealMaterial;
import com.lngsyz.ywtb.enumeration.SealMaterialElec;
import com.lngsyz.ywtb.enumeration.SealType;
import com.lngsyz.ywtb.mapper.source1.YwtbCityOrderSealMapper;

import net.logstash.logback.encoder.org.apache.commons.lang.StringUtils;

@Service
public class YwtbCityOrderSealService {
    
	@Autowired
	YwtbCityOrderSealMapper ywtbCityOrderSealMapper;
	
    public List<SealInfo> findByMainId(String mainId){
    	List<SealInfo> rtn = new ArrayList<SealInfo>();
    	Map<String, Object> param = new HashMap<String, Object>();
    	if(StringUtils.isNotBlank(mainId)) {
    		param.put("mainId", mainId);
    		List<YwtbCityOrderSeal> lists = ywtbCityOrderSealMapper.findByCondition(param);
    		for(YwtbCityOrderSeal ycos : lists) {
    			SealInfo si = new SealInfo();
    			si.setTypeName(SealType.getNameByKey(ycos.getSealType()));
    			// 物理
    			if(StringUtils.equals(ycos.getSealMedia(), "1")) {
    				si.setMaterial(SealMaterial.getNameByKey(ycos.getSealMaterial()));
    			} else if(StringUtils.equals(ycos.getSealMedia(), "1")) {
    				si.setMaterial(SealMaterialElec.getNameByKey(ycos.getSealMaterial()));
    			}
    			si.setPrice(ycos.getPrice());
    			si.setReferSealId(ycos.getReferSealId());
    			rtn.add(si);
    		}
    	}
    	return rtn;
    }
    
    public List<YwtbCityOrderSeal> findByCondition(String mainId){
    	if(StringUtils.isNotBlank(mainId)) {
    		Map<String, Object> ycosParam = new HashMap<String, Object>();
    		ycosParam.put("mainId", mainId);
    		return ywtbCityOrderSealMapper.findByCondition(ycosParam);
    	} else {
    		return new ArrayList<YwtbCityOrderSeal>();
    	}
    }
    
    public void inserts(List<YwtbCityOrderSeal> seals) {
    	if(seals != null && seals.size() > 0) {
    		ywtbCityOrderSealMapper.inserts(seals);
    	}
    }
    
    public int updateBz(String mainId) {
    	Map<String, Object> param = new HashMap<String, Object>();
		param.put("mainId", mainId);
		return ywtbCityOrderSealMapper.updateBz(param);
    }
}
